package com.example.flshtarvel.service;

import com.example.flshtarvel.entity.ArticleLikeMap;

import com.example.flshtarvel.mapper.ArticleLikeMapMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArticleLikeMapService {
    @Autowired(required = false)
    ArticleLikeMapMapper articleLikeMapMapper;

    //信息点赞
    public int ArticleLike(String articleId, String userId){
        List<ArticleLikeMap> articleLikeMaps = articleLikeMapMapper.selectArticleLikeByArticleIdAndUserId(articleId,userId);

        if(articleLikeMaps.size()==0 || articleLikeMaps==null){
            int result = articleLikeMapMapper.ArticleLike(articleId,userId);
            return result;
        }else{
            return 0;
        }
    }

    //取消点赞
    public int deleteArticleLike(String articleId,String userId){
        int result = articleLikeMapMapper.deleteArticleLike(articleId,userId);
        return result;
    }

    //查询点赞    根据信息id 用户id
    public int selectArticleLikeByArticleIdAndUserId(String articleId, String userId){
        List<ArticleLikeMap> articleLikeMaps = articleLikeMapMapper.selectArticleLikeByArticleIdAndUserId(articleId,userId);
        int result;
        if(articleLikeMaps.size()==0||articleLikeMaps==null){
            result=0;
        }else{
            result=1;
        }
        return result;
    }

    //查询点赞数    根据信息id
    public int selectArticleLikeByArticleId(String articleId){
        int result = articleLikeMapMapper.selectArticleLikeByArticleId(articleId);
        return result;
    }

}
